GetSchoolVouchersQueryHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 20
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A execute 0 16 2
1
import { QueryHandler } from '@nestjs/cqrs';
2
import { Inject } from '@nestjs/common';
3
import { GetSchoolVouchersQuery } from './GetSchoolVouchersQuery';
4
import { IVoucherRepository } from 'src/Domain/School/Repository/IVoucherRepository';
5
import { SchoolUserView } from '../../View/SchoolUserView';
6
7
@QueryHandler(GetSchoolVouchersQuery)
8
export class GetSchoolVouchersQueryHandler {
9
  constructor(
10
    @Inject('IVoucherRepository')
11
    private readonly voucherRepository: IVoucherRepository
12
  ) {}
13
14
  public async execute(query: GetSchoolVouchersQuery): Promise<SchoolUserView[]> {
15
    const schoolUserViews: SchoolUserView[] = [];
16
    const vouchers = await this.voucherRepository.findBySchool(query.schoolId);
17
18
    for (const voucher of vouchers) {
19
      schoolUserViews.push(
20
        new SchoolUserView(
21
          voucher.getId(),
22
          voucher.getEmail(),
23
          'voucher'
24
        )
25
      );
26
    }
27
28
    return schoolUserViews;
29
  }
30
}
31